package com.example.newapplication.EquipmentManage;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.newapplication.Bean.Abnormal;
import com.example.newapplication.Bean.DetailYijie;
import com.example.newapplication.Bean.HeadDate;
import com.example.newapplication.Bean.InnerDetail;
import com.example.newapplication.Bean.InnerHeadData;
import com.example.newapplication.Bean.Yijie;
import com.example.newapplication.Fragment.HeadFragment;
import com.example.newapplication.NetRequest;
import com.example.newapplication.R;
import com.google.gson.Gson;

import net.qiujuer.genius.kit.handler.Run;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class YijieEquipment extends AppCompatActivity {

    private ImageView back;
    private RecyclerView recyclerView;
    private List<InnerHeadData> list ;
    private List<Yijie.DataBean> yijie;
    private InnerDetail innerDetail;
    private int[] mipmap = new int[10];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yijie_equipment);

        init();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        list = new ArrayList<>();
        if(!list.isEmpty()){
            list.clear();
        }
        InnerHeadData innerHeadData1 = new InnerHeadData();
        innerHeadData1.machineName = "清扬 男士洗发水";
        innerHeadData1.machineCode = "RC_2021_1578";
        innerHeadData1.userName = "肖小韬";
        innerHeadData1.userId = "201801020210";
        list.add(innerHeadData1);
        innerHeadData1=null;

        InnerHeadData innerHeadData2 = new InnerHeadData();
        innerHeadData2.machineName = "英雄 高级钢笔";
        innerHeadData2.machineCode = "RC_2021_1588";
        innerHeadData2.userName = "小豪子";
        innerHeadData2.userId = "201801020233";
        list.add(innerHeadData2);
        innerHeadData2=null;
        InnerHeadData innerHeadData3 = new InnerHeadData();
        innerHeadData3.machineName = "Java 语言程序设计";
        innerHeadData3.machineCode = "BK_2021_1588";
        innerHeadData3.userName = "小波子";
        innerHeadData3.userId = "201801020217";
        list.add(innerHeadData3);
        innerHeadData3=null;
        InnerHeadData innerHeadData4 = new InnerHeadData();
        innerHeadData4.machineName = "绿联 RJ45水晶头";
        innerHeadData4.machineCode = "LJ_2021_1578";
        innerHeadData4.userName = "小结巴";
        innerHeadData4.userId = "201801020251";
        list.add(innerHeadData4);
        innerHeadData4=null;
        InnerHeadData innerHeadData5 = new InnerHeadData();
        innerHeadData5.machineName = "OPPO R15星云版";
        innerHeadData5.machineCode = "YD_2021_1578";
        innerHeadData5.userName = "山鸡哥";
        innerHeadData5.userId = "201801020280";
        list.add(innerHeadData5);
        innerHeadData5 = null;

        mipmap[0] = R.mipmap.tuijian1;
        mipmap[1] = R.mipmap.tuijian2;
        mipmap[2] = R.mipmap.tuijian3;
        mipmap[3] = R.mipmap.tuijian4;
        mipmap[4] = R.mipmap.tuijian5;
        mipmap[5] = R.mipmap.tuijian6;
        mipmap[6] = R.mipmap.tuijian7;
        mipmap[7] = R.mipmap.tuijian8;

        recyclerView.addItemDecoration(new HeadFragment.SpacesItemDecoration(10));
        recyclerView.setAdapter(new mAdapter());
        recyclerView.setLayoutManager(new LinearLayoutManager(YijieEquipment.this));
        recyclerView.setFocusableInTouchMode(false);//scrollView 嵌套 RecyclerView 显示时会滚动到RecyclerView第一项,让recyclerView去除焦点

    }

    private void init() {
        back = findViewById(R.id.imageView);
        recyclerView = findViewById(R.id.recy_yijie);
    }

    private class mAdapter extends RecyclerView.Adapter<mHolder>{

        @NonNull
        @Override
        public mHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(YijieEquipment.this).inflate(R.layout.item_yijie,parent,false);
            mHolder mholder = new mHolder(view);
            return mholder;
        }

        @Override
        public void onBindViewHolder(@NonNull mHolder holder, final int position) {
            holder.id.setText(list.get(position).machineCode);
            holder.name.setText(list.get(position).machineName);
            holder.id2.setText(list.get(position).userId);
            holder.name2.setText(list.get(position).userName);
            holder.image.setImageResource(mipmap[position]);
            holder.item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(YijieEquipment.this,R.style.noTitleDialog);
                    AlertDialog alert = builder.create();
                    View view = LayoutInflater.from(YijieEquipment.this).inflate(R.layout.dialog_yijie,null);

//                    TextView MachineName = view.findViewById(R.id.textView72);
//                    TextView MachineId = view.findViewById(R.id.textView74);
//                    TextView MachineType = view.findViewById(R.id.textView73);
//                    TextView data = view.findViewById(R.id.textView71);
//                    TextView manufacturer = view.findViewById(R.id.textView75);
//                    TextView startTime = view.findViewById(R.id.textView76);
//                    TextView oldYear = view.findViewById(R.id.textView77);
//                    TextView money = view.findViewById(R.id.textView78);
//                    TextView residual = view.findViewById(R.id.textView79);
//                    TextView job = view.findViewById(R.id.textView81);
//                    TextView userName = view.findViewById(R.id.textView82);
//                    TextView startDate = view.findViewById(R.id.textView85);
//                    TextView borrowTime = view.findViewById(R.id.textView83);
//                    TextView location = view.findViewById(R.id.textView84);
//
//                    MachineId.setText(detailYijie.getData().getMachineCode());
//                    MachineName.setText(innerDetail.getData().getMachineName());
//                    MachineType.setText(detailYijie.getData().getMachineType());
//                    data.setText(detailYijie.getData().getStartDate());
//                    manufacturer.setText(detailYijie.getData().getManufacturer());
//                    startTime.setText(detailYijie.getData().getBorrowTime());
//                    oldYear.setText(String.valueOf(detailYijie.getData().getOldYear()));
//                    money.setText(String.valueOf(detailYijie.getData().getMoney()));
//                    residual.setText(String.valueOf(detailYijie.getData().getResidual()));
//                    job.setText(detailYijie.getData().getJob());
//                    userName.setText(detailYijie.getData().getUserName());
//                    startDate.setText(detailYijie.getData().getStartDate());
//                    borrowTime.setText(detailYijie.getData().getBorrowTime());
//                    location.setText(detailYijie.getData().getLocation());



                    alert.setView(view);
                    alert.show();
                    WindowManager.LayoutParams params = alert.getWindow().getAttributes();
                    params.width = 1050;
                    params.height = 1300;
                    alert.getWindow().setAttributes(params);
                }
            });
        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }
    private class mHolder extends RecyclerView.ViewHolder{

        TextView id,name,id2,name2;
        ImageView image;
        ConstraintLayout item;
        public mHolder(@NonNull View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.imageView5);
            id = itemView.findViewById(R.id.textView21);
            name = itemView.findViewById(R.id.textView22);
            id2 = itemView.findViewById(R.id.textView19);
            name2 = itemView.findViewById(R.id.textView12);
            item = itemView.findViewById(R.id.yijie_item);
        }
    }
}